/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package supportlearning.session;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import supportlearning.entities.Account;
import supportlearning.entities.Semester;
import supportlearning.entities.StaffProfile;

/**
 *
 * @author Huy
 */
@Stateless
public class createstaffprofile implements createstaffprofileLocal {
    @PersistenceContext(unitName = "eprojectSupportLearning-ejbPU")
    private EntityManager em;

        public int CreateStaffProfile(int id, String Desc, int SemID) {
        Account acc = em.find(Account.class, id);
        Semester sem = em.find(Semester.class, SemID);
        if (acc == null) {
            return 1;//AccountID is valid
        } else if (sem == null) {
            return 2;//SemesterID is valid
        } else {
            StaffProfile staff = new StaffProfile();
            staff.setAccount(acc);
            staff.setDescription(Desc);
            staff.setSemesterId(SemID);
            em.persist(staff);
            return 3;//ok
        }
    }

    public void persist(Object object) {
        em.persist(object);
    }
  
}
